package com.musemun.controller;

import com.musemun.common.CommonResult;
import com.musemun.common.ResultCode;
import com.musemun.common.ResultUtil;
import com.musemun.exception.ApiException;
import com.musemun.service.function.LendContact;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/crms/outAdmin")
@Api(tags="文物出库模块")
public class OutController {

    @Resource
    LendContact lendContact;

    @PostMapping("/insertBatch")
    @Transactional
    public CommonResult insertBatch(MultipartFile file) {
        InputStream inputStream = null;
        try {
            inputStream = file.getInputStream();
        } catch (IOException e) {
            throw new ApiException(ResultCode.File_ERROR);
        }
        boolean flag = lendContact.insertBatch(inputStream);
        Map<String, Boolean> map = new HashMap<>();
        map.put("flag", flag);
        return ResultUtil.success(map);
    }


}
